#include <iostream>
#include <string>
#include <cmath>
#include <unordered_map>

using namespace std;

bool is_prime(int n) {
  if (n <= 1) {
    return false;
  }
  for (int i = 2; i <= sqrt(n); ++i) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

int find_closest_prime(int n) {
  if (is_prime(n)) {
    return n;
  }
  int step = 1;
  while (true) {
    if (is_prime(n - step)) {
      return n - step;
    }
    if (is_prime(n + step)) {
      return n + step;
    }
    step += 1;
  }
}

int main() {
  unordered_map<string, int> word_to_digit = {
    {"zero", 0},
    {"one", 1},
    {"two", 2},
    {"three", 3},
    {"four", 4},
    {"five", 5},
    {"six", 6},
    {"seven", 7},
    {"eight", 8},
    {"nine", 9},
  };

  string input_str;
  getline(cin, input_str); 

  string words[3];
  int wordCount = 0;
  string currentWord = "";

  for (char c : input_str) {
    if (c == ' ' && !currentWord.empty()) {
      words[wordCount++] = currentWord;
      currentWord = "";
    } else if (c != ' ') {
      currentWord += c;
    }
  }
  if (!currentWord.empty()) {
    words[wordCount++] = currentWord;
  }

  if (wordCount != 3) {
    cout << "Wrong input" << endl;
    return 0; 
  }

  try {
    int number = word_to_digit.at(words[0]) * 100 + 
                 word_to_digit.at(words[1]) * 10 + 
                 word_to_digit.at(words[2]);
    if (100 <= number && number <= 999) {
      cout << find_closest_prime(number) << endl;
    } else {
      cout << "Wrong input" << endl;
    }
  } catch (const out_of_range& e) {
    cout << "Wrong input" << endl;
  }

  return 0;
}
